<?php
   //添加商品到数据库 获取三个参数 name price num

   //获取前端传过来的参数
   $name = $_GET['name'];
   $price = $_GET['price'];
   $num = $_GET['num'];

   $conn = mysqli_connect('localhost', 'root', 'root', '2008');
   mysqli_query($conn, "set charset 'utf8'");
   mysqli_query($conn, "set character set 'utf8'");

   //如果字段在数据库是字符串 要加引号
   $sql = "insert into shop (name,price,num) values ('$name',$price,$num)";
   $res = mysqli_query($conn,$sql);
   // $res = false;
   if($res){
      echo json_encode(array(
         'code' => 200,
         'body' => array(
            'msg' => '添加成功'
         )
         ));
   }else{
      echo json_encode(array(
         'code' => 201,
         'body' => array(
            'msg' => '网络错误,请重试'
         )
         ));
   }
?>